home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************
- #
- # CustomApp.c
- #
- # CustomApp.c includes many of the routines required to customize the shell app, such
- # as initialization and termination routines. Ideally, shell.c should not need to be
- # modified.
- #
- # Author: Timothy Carroll
- # Apple Developer Technical Support
- # timc@apple.com
- #
- # Revision: Jason Yeo
- #
- # Modification History:
- #
- # 2/9/97 TMC Initial Release
- #
- # 9/12/97 JY Updated for:
- # TEC 1.2.1
- # Universal Interfaces 3.0
- # CodeWarrior 11 projects
- #
- # Copyright © 1997 Apple Computer, Inc., All Rights Reserved
- #
- #
- # You may incorporate this sample code into your applications without
- # restriction, though the sample code has been provided "AS IS" and the
- # responsibility for its operation is 100% yours. However, what you are
- # not permitted to do is to redistribute the source as "DSC Sample Code"
- # after having made changes. If you're going to re-distribute the source,
- # we require that you make it clear in the source that the code was
- # descended from Apple Sample Code, but that you've made changes.
- #
- *************************************************************************************/
-
- #include "CustomApp.h"
- #include "Encoder.h"
- #include "Sound.h"
-
- static OSStatus HandleMenus (SInt32 menuResult);
-
-
- OSStatus InitApp (void)
- {
- OSStatus theErr = noErr;
- Handle menuBarH = NULL;
- MenuRef appleMenuH = NULL;
-
- // Load and install the menu bar.
- menuBarH = GetNewMBar(rMenuBar);
- FAIL_NIL (menuBarH, "\pError: Unable to load the Menubar.")
-
- SetMenuBar(menuBarH);
- DisposeHandle(menuBarH);
-
- // Add all of the standard items to the Apple Menu.
- appleMenuH = GetMenuHandle(mAppleMenu);
- FAIL_NIL (appleMenuH, "\pError: Couldn't find Apple Menu")
- AppendResMenu(appleMenuH, 'DRVR');
-
- DrawMenuBar();
-
- // We're done, go cleanup
- goto cleanup;
-
- error:
- if (theErr == noErr)
- theErr = paramErr;
-
- cleanup:
- return theErr;
- }
-
-
- OSStatus TerminateApp (void)
- {
-
- return noErr;
- }
-
-
- Boolean AppWantsTime (void)
- {
- return false;
- }
-
-
- OSStatus TimeSlice (void)
- {
- return noErr;
- }
-
- OSStatus HandleEvent (EventRecord *theEvent)
- {
- OSStatus theErr = noErr;
- WindowRef whichWindow = NULL;
- SInt16 part;
-
- switch (theEvent->what)
- {
- case nullEvent:
- break;
-
- case mouseDown:
- part = FindWindow(theEvent->where,&whichWindow);
- switch(part)
- {
- case inMenuBar:
- theErr = HandleMenus(MenuSelect(theEvent->where));
- break;
-
- case inSysWindow:
- SystemClick(theEvent, (GrafPtr) whichWindow);
- break;
-
- default:
- break;
- }
- break;
-
- case osEvt:
- switch ((theEvent->message & osEvtMessageMask) >> 24)
- {
- case mouseMovedMessage:
- break;
-
- case suspendResumeMessage:
- gAppForeGround = !gAppForeGround;
- break;
- }
- break;
-
- case kHighLevelEvent:
- theErr = AEProcessAppleEvent(theEvent);
- break;
-
- case keyDown:
- if (theEvent->modifiers & cmdKey)
- {
- theErr = HandleMenus (MenuKey((short) theEvent->message & charCodeMask));
- }
- else
- {
-
- }
- break;
-
- default:
- break;
- };
-
-
- InitCursor (); // Return the cursor to a standard arrow.
- return theErr;
- }
-
- pascal OSErr HandleOpenAppEvent (AppleEvent *event, AppleEvent *reply,long refCon)
- {
- OSErr theErr = noErr;
- theErr = CheckAppleEventForMissingParams (event);
- if (theErr != noErr)
- return theErr;
-
- // Do we want to do anything special here? I doubt it!
- return noErr;
-
- #pragma unused reply
- #pragma unused refcon
- }
-
-
- pascal OSErr HandleOpenDocEvent (AppleEvent *event, AppleEvent *reply,long refCon)
- {
- OSErr theErr = noErr;
- AEDescList docsList;
- SInt32 loop, docCount;
- DescType type;
- Size docSize;
- FSSpec file;
- AEKeyword keyword;
-
- docsList.dataHandle = NULL;
-
- theErr = AEGetParamDesc(event,keyDirectObject,typeAEList,&docsList);
- FAIL_OSERR (theErr, "\pError: Failed to retrieve document list in ODOC")
-
- theErr = CheckAppleEventForMissingParams (event);
- FAIL_OSERR (theErr, "\pError: Missing parameters in ODOC")
-
- // Find out how many items were passed into us.
- theErr = AECountItems (&docsList, &docCount);
- FAIL_OSERR (theErr, "\pError: Failed to get a document count in ODOC")
-
- for (loop = 1; loop <= docCount; loop++)
- {
- theErr = AEGetNthPtr(&docsList,loop,typeFSS,&keyword,&type,
- (Ptr) &file,sizeof(file),&docSize);
- FAIL_OSERR (theErr, "\pError: Failed to retrieve the FSSpec in ODOC")
-
- EncodeFile (&file);
- }
-
- goto cleanup;
-
- error:
- if (theErr == noErr)
- theErr = paramErr;
- cleanup:
- if (docsList.dataHandle != NULL)
- (void) AEDisposeDesc(&docsList);
- return theErr;
-
-
-
- #pragma unused reply
- #pragma unused refcon
- }
-
- pascal OSErr HandlePrintDocEvent (AppleEvent *event, AppleEvent *reply,long refCon)
- {
- // We don't do printing
- return errAEEventNotHandled;
-
- #pragma unused event
- #pragma unused reply
- #pragma unused refcon
- }
-
- pascal OSErr HandleQuitAppEvent (AppleEvent *event, AppleEvent *reply,long refCon)
- {
- OSErr theErr = noErr;
- theErr = CheckAppleEventForMissingParams (event);
- if (theErr != noErr)
- return theErr;
-
- gQuittingApp = true;
- return theErr;
-
- #pragma unused reply
- #pragma unused refcon
- }
-
-
- OSStatus HandleMenus (SInt32 menuResult)
- {
- OSStatus theErr = noErr;
- SInt16 theMenu, theItem;
-
- theMenu = (menuResult >> 16) & 0x0000FFFF;
- theItem = (menuResult) & 0x0000FFFF;
-
- switch (theMenu)
- {
- case mAppleMenu:
- if (theItem == iAboutApp)
- SysBeep(2);
- else
- {
- // Find out the name of the Apple menu item and open the "desk accessory"
- Str255 name;
- MenuHandle appleMenuH = NULL;
-
- appleMenuH = GetMenuHandle (mAppleMenu);
- FAIL_NIL (appleMenuH, "\pError: Unable to retrieve the Apple menu")
-
- GetMenuItemText(appleMenuH,theItem,name);
- (void) OpenDeskAcc(name);
- }
- break;
- case mFileMenu:
- switch (theItem)
- {
- case iConvert:
- // Open a standard files dialog and choose a text file to convert.
- // TO DO: This should generate an Apple Event instead of directly calling.
- {
- StandardFileReply inputFile;
- SFTypeList typeList;
-
- typeList[0] = 'TEXT';
-
- StandardGetFile (NULL, 1, typeList, &inputFile);
-
- if (inputFile.sfGood)
- EncodeFile (&inputFile.sfFile);
- }
- break;
-
- case iQuit:
- theErr = DispatchQuitEvent();
- break;
- };
- break;
-
- case mEditMenu:
- if (theItem == iPreferences)
- theErr = EditPreferences (&gPreferences);
- break;
- }
-
- goto cleanup;
-
- error:
- if (theErr == noErr)
- theErr = paramErr;
-
- cleanup:
- HiliteMenu(0);
- return theErr;
- }